package com.sanpu.kxe.module.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.business.main.bean.CheckVersionOutput;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Description：版本更新弹框
 * Created by 薛勇军 on 2019/1/11.
 */

public class CheckVersionDialog extends Dialog {

    @Bind(R.id.versionRemarkTv)
    TextView versionRemarkTv;

    private String updateDownloadPath;

    public CheckVersionDialog(Context context, CheckVersionOutput retDatBean) {
        super(context, R.style.dialog_normal);
        setContentView(R.layout.view_check_version);
        ButterKnife.bind(this);

        if (retDatBean != null) {
            if (TextUtils.equals("FORCE", retDatBean.getUpdateMethod())) {
                setCancelable(false);
            } else {
                setCancelable(true);
            }
            if (!TextUtils.isEmpty(retDatBean.getUpdateInfo())) {
                versionRemarkTv.setText(retDatBean.getUpdateInfo());
            }
            if (!TextUtils.isEmpty(retDatBean.getUpdateDownloadPath())) {
                updateDownloadPath = retDatBean.getUpdateDownloadPath();
            }
        }
    }

    @OnClick({R.id.comfirmRtv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.comfirmRtv:
                if (!TextUtils.isEmpty(updateDownloadPath)) {
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.VIEW");
                    Uri content_url = Uri.parse(updateDownloadPath);
                    intent.setData(content_url);
                    getContext().startActivity(intent);
                }
                break;
        }
    }

}
